package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.mapper.AnswerMapper;
import cn.wolfcode.trip.base.service.IAnswerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AnswerServiceImpl implements IAnswerService {
    @Autowired
    private AnswerMapper answerMapper;

    @Override
    public PageInfo<Answer> selectAnswerByQuestionId(Long id) {
        PageHelper.startPage(1,0);
        List<Answer> list = answerMapper.selectByQuestionId(id);
        return new PageInfo<>(list);
    }

    @Override
    public void save(Answer answer) {
        answer.setCreateTime(new Date());
        answerMapper.insert(answer);
    }

    @Override
    public void changeState(Long id) {
        answerMapper.updateState(id);
    }
}
